package com.jsh.erp.service.scorder;

import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * gaoqijun
 */
@Service(value = "scorder_component")
@ScOrderResource
public class ScOrderComponent implements ICommonQuery {

    @Resource
    private ScOrderService scOrderService;

    @Override
    public Object selectOne(Long id) throws Exception {
        return scOrderService.getScOrder(id);
    }

    @Override
    public List<?> select(Map<String, String> map,HttpServletRequest request)throws Exception {
        return getOrderList(map);
    }

    private List<?> getOrderList(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        String khxx = StringUtil.getInfo(search, "khxx");
        String guige = StringUtil.getInfo(search, "guige");
        String beignTime = StringUtil.getInfo(search, "beginTime");
        String endTime = StringUtil.getInfo(search, "endTime");
        String ddNum = StringUtil.getInfo(search, "ddNum");
        String status = StringUtil.getInfo(search, "status");
        String order = QueryUtils.order(map);
        return scOrderService.select(khxx,guige,beignTime,ddNum,endTime,status,QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public Long counts(Map<String, String> map,HttpServletRequest request) throws Exception{
        String search = map.get(Constants.SEARCH);
        String khxx = StringUtil.getInfo(search, "khxx");
        String guige = StringUtil.getInfo(search, "guige");
        String beignTime = StringUtil.getInfo(search, "beginTime");
        String endTime = StringUtil.getInfo(search, "endTime");
        String ddNum = StringUtil.getInfo(search, "ddNum");
        String status = StringUtil.getInfo(search, "status");
        return scOrderService.countOrder(khxx,guige,beignTime,endTime,ddNum,status);
    }

    @Override
    public int insert(String beanJson, HttpServletRequest request)throws Exception {
        return scOrderService.insertScOrder(beanJson, request);
    }

    @Override
    public int update(String beanJson, Long id, HttpServletRequest request)throws Exception {
        return scOrderService.updateScOrder(beanJson, id, request);
    }

    @Override
    public int delete(Long id, HttpServletRequest request)throws Exception {
        return scOrderService.deleteScOrder(id, request);
    }

    @Override
    public int batchDelete(String ids, HttpServletRequest request)throws Exception {
        return scOrderService.batchDeleteScOrder(ids, request);
    }

    @Override
    public int checkIsNameExist(Long id, String name)throws Exception {
        return 0;
    }

}
